package com.zhentao.equipment.controller;

import com.zhentao.equipment.service.DeviceStatusService;
import com.zhentao.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 在线状态与状态日志接口
 */
@RestController
@RequestMapping("/api/devices")
@CrossOrigin(origins = "*")
public class DeviceStatusController {

    @Autowired
    private DeviceStatusService service;

    /** 查询设备是否在线（默认超时30分钟） */
    @GetMapping("/{id}/online")
    public ResultVo online(@PathVariable("id") Long deviceId, @RequestParam(required = false) Long timeoutMillis) {
        long tm = timeoutMillis == null ? 30 * 60 * 1000L : timeoutMillis;
        return service.online(deviceId, tm);
    }

    /** 分页查询状态日志 */
    @GetMapping("/{id}/status-logs")
    public ResultVo logs(@PathVariable("id") Long deviceId,
                         @RequestParam(required = false) Integer pageNum,
                         @RequestParam(required = false) Integer pageSize) {
        return service.logs(deviceId, pageNum, pageSize);
    }
}





